import { Module } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Redis } from 'ioredis';
import { RedisService } from './redis.service';

@Module({
  imports: [],
  providers: [
    RedisService,
    {
      inject: [ConfigService],
      provide: 'REDIS_CLIENT',
      useFactory: (configService: ConfigService) => {
        const client = new Redis(configService.get('REDIS_URL'));
        return client;
      },
    },
  ],
  exports: [RedisService, RedisModule],
})
export class RedisModule {}
